﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:mwt="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
                    xmlns:Docking="clr-namespace:Monti.Docking">

   <ResourceDictionary.MergedDictionaries>
      <ResourceDictionary Source="/Monti;component/Themes/Common.xaml" />
   </ResourceDictionary.MergedDictionaries>

   <Style x:Key="TabMenuItem" TargetType="{x:Type MenuItem}">
      <Setter Property="Header" Value="{Binding Path=Title}" />
      <Setter Property="ToolTip" Value="{Binding Path=ToolTip}" />
      <Setter Property="IsEnabled" Value="{Binding Path=IsEnabled}" />
      <Setter Property="IsCheckable" Value="{Binding Path=IsEnabled}" />
      <Setter Property="IsChecked" Value="{Binding Path=IsSelected, Mode=TwoWay}" />
      <Style.Triggers>
         <Trigger Property="IsEnabled" Value="False">
            <Setter Property="Foreground" Value="{StaticResource MetroDisabledText}"/>
         </Trigger>
      </Style.Triggers>
   </Style>

   <Style x:Key="TabMenuButtonStyle" TargetType="{x:Type MenuItem}">
      <Setter Property="Focusable" Value="False"/>
      <Setter Property="Height" Value="16"/>
      <Setter Property="Width" Value="16"/>
      <Setter Property="Template">
         <Setter.Value>
            <ControlTemplate TargetType="{x:Type MenuItem}">
               <Border Name="ButtonBorder" Margin="1"
                       Background="{StaticResource TabItemCloseButtonNormalBackgroundBrush}"
                       BorderBrush="{StaticResource TabItemCloseButtonNormalBorderBrush}"
                       CornerRadius="1" BorderThickness="1">
                  <Grid>
                     <ContentPresenter ContentSource="Header" 
                                       HorizontalAlignment="Stretch"
                                       VerticalAlignment="Stretch">
                        <ContentPresenter.Content>
                           <Path Style="{StaticResource TabMenuPath}" />
                        </ContentPresenter.Content>
                     </ContentPresenter>
                     <Popup Name="Popup"
                            Placement="Bottom"
                            IsOpen="{TemplateBinding IsSubmenuOpen}"
                            AllowsTransparency="True" 
                            Focusable="False"
                            PopupAnimation="Fade">
                        <mwt:SystemDropShadowChrome Color="#71000000" 
                                                    CornerRadius="1"
                                                    Margin="0,0,8,8"
                                                    SnapsToDevicePixels="True">
                           <Border Name="SubmenuBorder"
                                   Margin="1"
                                   SnapsToDevicePixels="True"
                                   BorderBrush="{StaticResource LineButtonBorderBrush}" 
                                   Background="{StaticResource MetroBaseBackground}" 
                                   CornerRadius="1" 
                                   BorderThickness="1">
                              <StackPanel IsItemsHost="True" 
                                          KeyboardNavigation.DirectionalNavigation="Cycle" />
                           </Border>
                        </mwt:SystemDropShadowChrome>
                     </Popup>
                  </Grid>
               </Border>
               <ControlTemplate.Triggers>
                  <Trigger Property="IsHighlighted" Value="true">
                     <Setter TargetName="ButtonBorder" Property="Background" 
                             Value="#D8D8D9" />
                  </Trigger>
               </ControlTemplate.Triggers>
            </ControlTemplate>
         </Setter.Value>
      </Setter>
   </Style>

   <!-- Control Template for DockSite -->
   <ControlTemplate x:Key="DockSiteTemplate" TargetType="{x:Type Docking:DockSite}">
      <Grid SnapsToDevicePixels="True" ClipToBounds="true" KeyboardNavigation.TabNavigation="Local">

         <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="Auto"/>
         </Grid.ColumnDefinitions>

         <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
         </Grid.RowDefinitions>
         
         <!-- This if for an auto hide tab group... -->
         <Border Grid.Row="0"
                 Grid.Column="0"
                 Grid.ColumnSpan="3"
                 Background="#EBEBEB"
                 BorderBrush="Black"
                 BorderThickness="1,1,1,0"
                 x:Name="ToolWindowTitle"
                 Visibility="{Binding RelativeSource={RelativeSource TemplatedParent},
                                       Path=IsToolWindow, Converter={StaticResource boolConverter}}">
            <Grid>
               <Grid.ColumnDefinitions>
                  <ColumnDefinition Width="*" />
                  <ColumnDefinition Width="Auto" />
                  <ColumnDefinition Width="Auto" />
                  <ColumnDefinition Width="Auto" />
               </Grid.ColumnDefinitions>
               
               <TextBlock Grid.Column="0"
                          x:Name="ToolWindowTitleText"
                          Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=SelectedItem.Title}" />
   
   
               <Menu Background="Transparent"
                     Grid.Column="1">
                  <MenuItem Style="{StaticResource TabMenuButtonStyle}"
                            ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Docking:DockSite}}, Path=Group.Items}"
                            ItemContainerStyle="{StaticResource TabMenuItem}">
                  </MenuItem>
               </Menu>
   
               <Button x:Name="PART_PinButton"
                       Focusable="False"
                       IsTabStop="False"
                       Style="{StaticResource PinButtonStyle}"
                       Grid.Column="2" />
   
               <Button x:Name="PART_CloseButton"
                       Focusable="False"
                       IsTabStop="False"
                       Style="{StaticResource TabItemCloseButtonStyle}"
                       Visibility="{Binding Path=SelectedContent.AllowClose, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource boolConverter}}"
                       Command="{Binding Path=CloseCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Docking:DockManager}}}"
                       CommandParameter="{Binding RelativeSource={RelativeSource TemplatedParent}}"
                       Grid.Column="3" />
            </Grid>
         </Border>

         <!-- TAB PANEL -->
         <Border BorderBrush="Black"
                 x:Name="TabPanelBorder"
                 BorderThickness="{Binding Path=IsToolWindow,
                                           Converter={StaticResource dockBorderConverter},
                                           ConverterParameter=TabPanel,
                                           RelativeSource={RelativeSource TemplatedParent}}"
                 Grid.Column="{Binding Path=TabStripPlacement, 
                                  Converter={StaticResource colConverter}, 
                                  RelativeSource={RelativeSource TemplatedParent}}">
            <Grid.Row>
               <MultiBinding Converter="{StaticResource rowConverter}">
                  <Binding Path="IsToolWindow">
                     <Binding.RelativeSource>
                        <RelativeSource Mode="TemplatedParent" />
                     </Binding.RelativeSource>
                  </Binding>
                  <Binding Path="TabStripPlacement">
                     <Binding.RelativeSource>
                        <RelativeSource Mode="TemplatedParent" />
                     </Binding.RelativeSource>
                  </Binding>
               </MultiBinding>
            </Grid.Row>
            <Grid Name="TabPanelGrid"
                  Background="#EBEBEB">
               
               <Grid.ColumnDefinitions>
                  <ColumnDefinition Width="*" />
                  <ColumnDefinition Width="Auto" />
               </Grid.ColumnDefinitions>

                  <ScrollViewer x:Name="PART_ScrollViewer"
                                CanContentScroll="True"
                                Visibility="Visible"
                                Grid.Column="0"
                                VerticalScrollBarVisibility="Hidden"
                                HorizontalScrollBarVisibility="Hidden">
                     <Docking:ScrollableTabPanel x:Name="TabPanel"
                                                 IsItemsHost="True"
                                                 Visibility="Visible"
                                                 SnapsToDevicePixels="True" />
                  </ScrollViewer>

                  <StackPanel VerticalAlignment="Bottom" Orientation="Horizontal" Grid.Column="1">

                     <Menu Background="Transparent">
                        <MenuItem Style="{StaticResource TabMenuButtonStyle}"
                               ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Docking:DockSite}}, Path=Group.Items}"
                               ItemContainerStyle="{StaticResource TabMenuItem}">
                        </MenuItem>
                     </Menu>

                  </StackPanel>

            </Grid>
         </Border>

         <!-- TAB CONTENT-->
         <Border BorderThickness="{Binding Path=IsToolWindow, Converter={StaticResource dockBorderConverter}, RelativeSource={RelativeSource TemplatedParent}}" 
                 Grid.Column="1" Grid.Row="2"
                 x:Name="PART_ContentBorder"
                 BorderBrush="Black" 
                 Background="#D8D8D9">
            <!-- This is the first/outer Border drawn on the TabPage -->
            <Border BorderThickness="0"
                    Background="White"
                    CornerRadius="{Binding Path=TabStripPlacement, Converter={StaticResource dockBorderConverter}, RelativeSource={RelativeSource TemplatedParent}}"
                    Margin="{Binding Path=IsToolWindow, Converter={StaticResource dockBorderConverter}, RelativeSource={RelativeSource TemplatedParent}, ConverterParameter=Margin}">
               <ContentControl x:Name="PART_SelectedContentHost"
										Content="{TemplateBinding SelectedContent}"
										ContentTemplate="{TemplateBinding SelectedContentTemplate}"
                              ContentTemplateSelector="{Binding Path=DockMan.TemplateSelector, RelativeSource={RelativeSource TemplatedParent}}"
										Foreground="{TemplateBinding Foreground}" IsTabStop="False"
										Padding="{TemplateBinding Padding}" />
            </Border>
         </Border>
      </Grid>

      <ControlTemplate.Triggers>
         <Trigger Property="HasActiveContent"
                  Value="True">
            <Setter TargetName="ToolWindowTitle"
                    Property="Background"
                    Value="#3A87AD" />
            <Setter TargetName="ToolWindowTitleText"
                    Property="Foreground"
                    Value="White" />
            <Setter TargetName="PART_ContentBorder"
                    Property="Background"
                    Value="#3A87AD" />
         </Trigger>

         <MultiTrigger>
            <MultiTrigger.Conditions>
               <Condition Property="IsToolWindow"
                          Value="True" />
               <Condition Property="ItemCount"
                          Value="1" />
            </MultiTrigger.Conditions>
            <MultiTrigger.Setters>
               <Setter TargetName="TabPanelBorder"
                       Property="Height"
                       Value="0px" />
            </MultiTrigger.Setters>
         </MultiTrigger>
      </ControlTemplate.Triggers>
   </ControlTemplate>

   <!-- TabControl Style, defines the look of the TabControl-->
   <Style TargetType="{x:Type Docking:DockSite}">
      <Setter Property="KeyboardNavigation.TabNavigation" Value="Cycle"/>
      <Setter Property="KeyboardNavigation.DirectionalNavigation" Value="Cycle"/>

      <Setter Property="Background" Value="{StaticResource TabControl_BackgroundBrush_Base}"/>
      <Setter Property="BorderThickness" Value="0"/>

      <Setter Property="Template" Value="{StaticResource DockSiteTemplate}"/>
   </Style>

</ResourceDictionary>